<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>项目编码</td>
                    <td>
                        <input type="text" v-model="healthy.bcode" disabled>
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">* </span>康复理疗项目名称</td>
                    <td>
                        <input type="text" v-model="healthy.bname">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">* </span>服务人数</td>
                    <td>
                        <input type="text" v-model="healthy.bpeople">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">* </span>服务时长(小时)</td>
                    <td>
                        <input type="text" v-model="healthy.bhour">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">* </span>服务费用(元)</td>
                    <td>
                        <input type="text" v-model="healthy.bmoney">
                    </td>
                </tr>
                <tr>
                    <td>项目状态</td>
                    <td>
                        <input type="radio" v-model="healthy.bstate" :value="true">启用
                        <input type="radio" v-model="healthy.bstate" :value="false">禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
    import { useRouter } from 'vue-router';
    import axios from 'axios';
    import { ref } from 'vue';
    import moment from 'moment';
    let router = useRouter();
    let healthy = ref
    ({
        "bid": 0,
        "bcode": moment(Date()).format("yyyyMMDD")+Math.random().toString().substring(2,5),
        "bname": "",
        "bpeople": 0,
        "bhour": 0,
        "bmoney": 0,
        "bdel": true,
        "bstate": true
    })
    const add = () => 
    {
        if (healthy.value.bname == "") 
        {
            alert("康复医疗项目名称不能为空")
            return;
        }
        if (healthy.value.bpeople == 0) 
        {
            alert("服务人数不能为空")
            return
        }
        if (healthy.value.bpeople * 0 != 0)
        {
            alert('服务人数只能是整数')
            return;
        }
        if (healthy.value.bhour == 0) 
        {
            alert("服务时长不能为空")
            return
        }
        if (healthy.value.bhour * 0 != 0) 
        {
            alert('服务时长只能是整数')
            return;
        }
        if (healthy.value.bmoney == 0) 
        {
            alert("服务费用不能为空")
            return
        }
        axios
        ({
            url: "https://localhost:7080/api/BodyHealthy/AddHealthy",
            method: "post",
            data: healthy.value
        })
        .then((res) => 
        {
            console.log(res);
            if (res.data > 0) 
            {
                alert("康复理疗信息添加成功")
                router.push('/allhealthy')
            }
            else 
            {
                alert('康复理疗信息添加失败')
            }
        })
        .catch((err) => 
        {
            console.log(err);
        })
}
</script>

<style lang="scss" scoped>

</style>